package com.accp.wxmp.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.WxMenu;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;

/**
 * Created by FirenzesEagle on 2016/6/1 0001.
 * Email:liumingbo2008@gmail.com
 */
public class MenuConfig {

    /**
     * 定义菜单结构
     *
     * @return
     */
    protected static WxMenu getMenu() {
        WxMenu menu = new WxMenu();
         WxMenu.WxMenuButton button1 = new  WxMenu.WxMenuButton();
        button1.setName("我是访客");
        button1.setType(WxConsts.BUTTON_CLICK);
        button1.setKey("visitor");
        WxMenu.WxMenuButton button2=new WxMenu.WxMenuButton();
        button2.setName("我是维修人员");
        button2.setType(WxConsts.BUTTON_CLICK);
        button2.setKey("engineer");
        WxMenu.WxMenuButton button3=new WxMenu.WxMenuButton();
        button3.setName("帮助");
        button3.setType(WxConsts.BUTTON_CLICK);
        button3.setKey("help");
        List<WxMenu.WxMenuButton> wxMenuButtons=new ArrayList<WxMenu.WxMenuButton>(16);
        wxMenuButtons.add(button1);
        wxMenuButtons.add(button2);
        wxMenuButtons.add(button3);
        menu.setButtons(wxMenuButtons);
        return menu;
    }

    /**
     * 运行此main函数即可生成公众号自定义菜单
     *
     * @param args
     */
    public static void main(String[] args) {
        MainConfig mainConfig = new MainConfig();
        WxMpService wxMpService = mainConfig.wxMpService();
        try {
            wxMpService.menuCreate(getMenu());
        } catch (WxErrorException e) {
            e.printStackTrace();
        }
    }

}
